package com.dingwei.lesyndrome.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.adapter.CheckNewsTypeAdapter;
import com.dingwei.lesyndrome.bean.GamCircleTypeBean;
import com.dingwei.lesyndrome.mvp.presenter.CheckNewsTypePresenter;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.SpaceDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.weight.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/6.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class CheckNewsTypeActivity extends BaseActivity implements Contract.CheckNewsView {

    CheckNewsTypePresenter checkNewsTypePresenter = new CheckNewsTypePresenter(this);
    @Bind(R.id.title_bar)
    TitleBar titleBar;
    @Bind(R.id.m_recyclerView)
    RecyclerView mRecyclerView;

    CheckNewsTypeAdapter adapter;
    GamCircleTypeBean bean;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_check_news_type;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        bean = (GamCircleTypeBean) getIntent().getSerializableExtra("bean");
        adapter = new CheckNewsTypeAdapter(BaseActivity.context);

        GridLayoutManager layoutManager = new GridLayoutManager(BaseActivity.context, 4);
        layoutManager.setSpanSizeLookup(adapter.obtainGridSpanSizeLookUp(4));
        SpaceDecoration itemDecoration = new SpaceDecoration((int) DisplayUtil.dip2px(BaseActivity.context, 8));//参数是距离宽度
        itemDecoration.setPaddingEdgeSide(false);//是否为左右2边添加padding.默认true.
        itemDecoration.setPaddingStart(false);//是否在给第一行的item添加上padding(不包含header).默认true.
        itemDecoration.setPaddingHeaderFooter(false);//是否对Header于Footer有效,默认false.

        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.addItemDecoration(itemDecoration);


        adapter.addAll(bean.data);
        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                intent  = new Intent();
                intent.putExtra("position",position);
                setResult(Activity.RESULT_OK,intent);
                finish();
            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
